package cn.csb.controller;


import cn.csb.domain.Boss;
import cn.csb.domain.Info;
import cn.csb.domain.Pet;
import cn.csb.service.PetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class WuLaLaController {

    @Autowired
    private PetService petService;

    @RequestMapping("/calculate.do")
    public Info calculate(@RequestBody Boss boss) {

        System.out.println(boss.getBfire());
        //计算公式：1+((宠火*王电+宠电*王地+宠地*王冰+宠冰*王火)-(王火*宠电+王电*宠地+王地*宠冰+王冰*宠火))*0.01*克制
        double demage=((boss.getPfire()*boss.getBelectricity()+boss.getPelectricity()*boss.getBsoil()
                        +boss.getPsoil()*boss.getBice()+boss.getPice()*boss.getBfire())
                 - (boss.getBfire()*boss.getPelectricity()+boss.getBelectricity()*boss.getPsoil()
                        +boss.getBsoil()*boss.getPice()+boss.getBice()*boss.getPfire()))
                 *boss.getPrestrain()*1.0/100;
        String mesg="伤害为:" +demage;
        System.out.println(mesg);
        Info info = new Info();
        info.setMessage(mesg);

        return info;
    }

    @RequestMapping("/counter.do")
    public Info counter(@RequestBody Boss boss) {

        List<Pet> list = petService.findAll();
        System.out.println(boss);
        System.out.println(list);
        Pet boss1=list.get(0);
        System.out.println(boss1);
        double max=((boss1.getPfire()*boss.getBelectricity()+boss1.getPelectricity()*boss.getBsoil()
                +boss1.getPsoil()*boss.getBice()+boss1.getPice()*boss.getBfire())
                - (boss.getBfire()*boss1.getPelectricity()+boss.getBelectricity()*boss1.getPsoil()
                +boss.getBsoil()*boss1.getPice()+boss.getBice()*boss1.getPfire()))
                *boss1.getPrestrain()*1.0/100;

        double a=0;
        int index=0;
        for (int i = 1; i < list.size(); i++) {
            Pet pet = list.get(i);
            a=((pet.getPfire()*boss.getBelectricity()+pet.getPelectricity()*boss.getBsoil()
                    +pet.getPsoil()*boss.getBice()+pet.getPice()*boss.getBfire())
                    - (boss.getBfire()*pet.getPelectricity()+boss.getBelectricity()*pet.getPsoil()
                    +boss.getBsoil()*pet.getPice()+boss.getBice()*pet.getPfire()))
                    *pet.getPrestrain()*1.0/100;
            if(a>=max){
                max=a;
                index=i;
            }
        }

        Info info = new Info();
        info.setMessage("请选择"+list.get(index).getPname()+","+"伤害加成为:"+max+"%");

        return info;
    }
}
